package com.konne.nightmare.FastPublicOpinion.ui.information.activity;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.BarUtils;
import com.blankj.utilcode.util.SizeUtils;
import com.blankj.utilcode.util.SpanUtils;
import com.konne.nightmare.FastPublicOpinion.R;
import com.konne.nightmare.FastPublicOpinion.base.BaseMvpActivity;
import com.konne.nightmare.FastPublicOpinion.base.BaseMvpPresenter;
import com.konne.nightmare.FastPublicOpinion.utils.LoadProgressDialog;
import com.konne.nightmare.FastPublicOpinion.widget.QJItemTitleView;
import com.konne.nightmare.FastPublicOpinion.widget.QJRadioGroup;

import java.util.ArrayList;
import java.util.List;

/**
 * Create by ws.
 * on Data:2022/2/13  Time:下午 2:57.
 * description: 抽题考试 .
 */
public class DrawExamAct extends BaseMvpActivity implements View.OnClickListener{
    public static void start(){
        ActivityUtils.startActivity(DrawExamAct.class);
    }
    @Override
    protected BaseMvpPresenter createPresenter() {
        return new BaseMvpPresenter();
    }

    @Override
    public int getLayout() {
        return R.layout.act_draw_exam;
    }

    @Override
    public void initView() {
        BarUtils.transparentStatusBar(this);
        BarUtils.setStatusBarLightMode(this,true);
        ((QJItemTitleView)findViewById(R.id.itv_draw_random)).setOnCheckedChangeListener(new QJItemTitleView.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(QJItemTitleView titleView, QJItemTitleView.Style style, boolean isChecked) {
            findViewById(R.id.ll_random).setVisibility(isChecked? View.VISIBLE:View.GONE);
            }
        });
        ((QJRadioGroup)findViewById(R.id.rg_type)).setOnCheckedChangeListener(new QJRadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(QJRadioGroup var1, int var2) {
                ViewGroup fl_content=findViewById(R.id.fl_content);
                if(var2==0){
                    fl_content.getChildAt(0).setVisibility(View.VISIBLE);
                    fl_content.getChildAt(1).setVisibility(View.GONE);
                    findViewById(R.id.view_line).setVisibility(View.VISIBLE);
                }else {
                    fl_content.getChildAt(0).setVisibility(View.GONE);
                    fl_content.getChildAt(1).setVisibility(View.VISIBLE);
                    findViewById(R.id.view_line).setVisibility(View.GONE);

                }
            }
        });
        findViewById(R.id.stv_submit).setOnClickListener(this);
        SpanUtils.with(findViewById(R.id.tv_point))
                .append("每张试卷")
                .append(" 2 ")
                .setForegroundColor(0xff3D92EB)
                .append("题").create();
        initQuestionType();
        initQuestionBlock();
    }

    private void initQuestionBlock() {
        ViewGroup fl_content=findViewById(R.id.fl_content);
        LinearLayout typeContent= (LinearLayout) ((ViewGroup)fl_content.getChildAt(1)).getChildAt(0);
        for (int i = 0; i < 6; i++) {
            typeContent.addView(getBlockItem(),new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, SizeUtils.dp2px(60)));
        }
        ViewGroup vp= (ViewGroup) LayoutInflater.from(this).inflate(R.layout.item_add_question,null);
        typeContent.addView(vp,new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, SizeUtils.dp2px(60)));
    }

    private void initQuestionType() {
        ViewGroup fl_content=findViewById(R.id.fl_content);
        LinearLayout typeContent= (LinearLayout) ((ViewGroup)fl_content.getChildAt(0)).getChildAt(0);
        List<String> datas=testTypeData();
        for (int i = 0; i <datas.size() ; i++) {
            typeContent.addView(getTypeItem(datas.get(i)),new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, SizeUtils.dp2px(55)));
        }
    }
    private View getBlockItem(){
        ViewGroup vp= (ViewGroup) LayoutInflater.from(this).inflate(R.layout.item_question_block,null);
        return vp;
    }
    private View getTypeItem(String txt){
        ViewGroup vp= (ViewGroup) LayoutInflater.from(this).inflate(R.layout.item_question_type,null);
        TextView tv= (TextView) vp.getChildAt(0);
        tv.setText(txt);
        return vp;
    }
    private List<String> testTypeData(){//测试获取题型数据
        List<String> datas=new ArrayList<>();
        datas.add("判断题");
        datas.add("单选题");
        datas.add("多选题");
        datas.add("填空题");
        datas.add("简答题");
        datas.add("不定项题");
        datas.add("文件题");
        return datas;
    }
    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.stv_submit:
                finish();
                break;
        }
    }

    @Override
    public void initData(Bundle savedInstanceState) {

    }

    @Override
    public LoadProgressDialog getLoadDialog() {
        return null;
    }

    @Override
    public void cancelLoadDialog() {

    }
}
